package com.ruoyi.basedocument.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedocument.domain.BomCostcenter;
import com.ruoyi.basedocument.service.IBomCostcenterService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 成本中心Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/bomcostestimation/basedocument/costcenter")
public class BomCostcenterController extends BaseController
{
    @Autowired
    private IBomCostcenterService bomCostcenterService;

    /**
     * 查询成本中心列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:costcenter:list')")
    @GetMapping("/list")
    public AjaxResult list(BomCostcenter bomCostcenter)
    {
        List<BomCostcenter> list = bomCostcenterService.selectBomCostcenterList(bomCostcenter);
        return success(list);
    }

    /**
     * 导出成本中心列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:costcenter:export')")
    @Log(title = "成本中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BomCostcenter bomCostcenter)
    {
        List<BomCostcenter> list = bomCostcenterService.selectBomCostcenterList(bomCostcenter);
        ExcelUtil<BomCostcenter> util = new ExcelUtil<BomCostcenter>(BomCostcenter.class);
        util.exportExcel(response, list, "成本中心数据");
    }

    /**
     * 获取成本中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:costcenter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(bomCostcenterService.selectBomCostcenterById(id));
    }

    /**
     * 新增成本中心
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:costcenter:add')")
    @Log(title = "成本中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BomCostcenter bomCostcenter)
    {
        return toAjax(bomCostcenterService.insertBomCostcenter(bomCostcenter));
    }

    /**
     * 修改成本中心
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:costcenter:edit')")
    @Log(title = "成本中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BomCostcenter bomCostcenter)
    {
        return toAjax(bomCostcenterService.updateBomCostcenter(bomCostcenter));
    }

    /**
     * 删除成本中心
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:costcenter:remove')")
    @Log(title = "成本中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bomCostcenterService.deleteBomCostcenterByIds(ids));
    }
}
